//
//  NSDate+XDTimerFormatter.m
//  tangchengyipin
//
//  Created by XiangDongMBP on 16/2/27.
//  Copyright © 2016年 XiangDong. All rights reserved.
//

#import "NSDate+XDTimerFormatter.h"

@implementation NSDate (XDTimerFormatter)

- (NSString *)xd_yyyyMMddHHmmss {
    NSDateFormatter * formatter = [[NSDateFormatter alloc] init];
    formatter.dateFormat = @"yyyy年MM月dd日 HH:mm:ss";
    return [formatter stringFromDate:self];
}
- (NSString *)xd_yyyy_MM_ddHHmmss {
    NSDateFormatter * formatter = [[NSDateFormatter alloc] init];
    formatter.dateFormat = @"yyyy-MM-dd HH:mm:ss";
    return [formatter stringFromDate:self];
}
- (NSString *)xd_yyyyMMddHHmm {
    NSDateFormatter * formatter = [[NSDateFormatter alloc] init];
    formatter.dateFormat = @"yyyy年MM月dd日 HH:mm";
    return [formatter stringFromDate:self];
}
- (NSString *)xd_yyyy_MM_ddHHmm {
    NSDateFormatter * formatter = [[NSDateFormatter alloc] init];
    formatter.dateFormat = @"yyyy-MM-dd HH:mm";
    return [formatter stringFromDate:self];
}
- (NSString *)xd_MMddHHmm {
    NSDateFormatter * formatter = [[NSDateFormatter alloc] init];
    formatter.dateFormat = @"MM月dd日 HH:mm";
    return [formatter stringFromDate:self];
}
- (NSString *)xd_MM_ddHHmm {        //!< 输出格式@"MM-dd HH:mm"
    NSDateFormatter * formatter = [[NSDateFormatter alloc] init];
    formatter.dateFormat = @"MM-dd HH:mm";
    return [formatter stringFromDate:self];
}
- (NSString *)xd_HHmm {             //!< 输出格式@"HH:mm"
    NSDateFormatter * formatter = [[NSDateFormatter alloc] init];
    formatter.dateFormat = @"HH:mm";
    return [formatter stringFromDate:self];
}
- (NSString *)xd_MMdd {
    NSDateFormatter * formatter = [[NSDateFormatter alloc] init];
    formatter.dateFormat = @"MM月dd日";
    return [formatter stringFromDate:self];
}
- (NSString *)xd_MM_dd {            //!< 输出格式@"MM/dd"
    NSDateFormatter * formatter = [[NSDateFormatter alloc] init];
    formatter.dateFormat = @"MM/dd";
    return [formatter stringFromDate:self];
}
- (NSString *)xd_yyyyMMdd {
    NSDateFormatter * formatter = [[NSDateFormatter alloc] init];
    formatter.dateFormat = @"yyyy年MM月dd日";
    return [formatter stringFromDate:self];
}
- (NSString *)xd_yyyy_MM_dd {      //!< 输出格式@"yyyy/MM/dd"
    NSDateFormatter * formatter = [[NSDateFormatter alloc] init];
    formatter.dateFormat = @"yyyy/MM/dd";
    return [formatter stringFromDate:self];
}
- (NSString *)xd_yyyy__MM__dd {      //!< 输出格式@"yyyy-MM-dd"
    NSDateFormatter * formatter = [[NSDateFormatter alloc] init];
    formatter.dateFormat = @"yyyy-MM-dd";
    return [formatter stringFromDate:self];
}
- (NSString *)xd_yyyyMM {
    NSDateFormatter * formatter = [[NSDateFormatter alloc] init];
    formatter.dateFormat = @"yyyy年MM月";
    return [formatter stringFromDate:self];
}

- (NSString *)xd_yyyy_MM {
    NSDateFormatter * formatter = [[NSDateFormatter alloc] init];
    formatter.dateFormat = @"yyyy/MM";
    return [formatter stringFromDate:self];
}

- (NSString *)xd_MM {
    NSDateFormatter * formatter = [[NSDateFormatter alloc] init];
    formatter.dateFormat = @"MM";
    return [formatter stringFromDate:self];
}

- (NSString *)xd_enWeek {
    NSDateFormatter * formatter = [[NSDateFormatter alloc] init];
    [formatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"]]; // 防止输出是中文
    formatter.dateFormat = @"ccc";
    return [formatter stringFromDate:self];
}

- (NSString *)xd_chatFriendlyStr {
    NSDate *startDate = [[NSCalendar currentCalendar] startOfDayForDate:[NSDate date]];
//    NSLog(@"今天起始时间 : %@", startDate.xd_yyyyMMddHHmmss);
    
    NSTimeInterval interval = [self timeIntervalSinceDate:startDate];
    NSString *str = nil;
    if (interval < 0) {
        str = [self xd_yyyy_MM_dd];
    } else {
        str = [self xd_HHmm];
    }
    return  str;
}

@end
